package com.example.mall.controller;

import com.example.mall.dao.PersonInfoDao;
import com.example.mall.dao.ShoppingCartDao;
import com.example.mall.model.CommodityInfo;
import com.example.mall.model.Order;
import com.example.mall.service.CommoityInfoService;
import com.example.mall.service.SellService;
import com.example.mall.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.ref.PhantomReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private PersonInfoDao personInfoDao;
    @Autowired
    private CommoityInfoService commoityInfoService;
    @Autowired
    private ShoppingCartDao shoppingCartDao;
    @Autowired
    private ShoppingService shoppingService;
    @Autowired
    private SellService sellService;

    @RequestMapping("/addAddress")
    public void addAddress() {
        shoppingService.addAddress(10001, "孙义皓", "13060070726", "四川大学江安校区");
    }

    @RequestMapping("/addCommodity")
    public void addCommodity() {
        List<String> tagnameList = new ArrayList<>();
        tagnameList.add("科普");
        tagnameList.add("计算机");
        commoityInfoService.addCommodity(20001, tagnameList, "C语言入门教程", "牛牛牛牛牛牛牛B", "http://", 5000, "成都", 100);
    }

    @RequestMapping("/getCommodityList")
    public List<CommodityInfo> getCommodityList() {
        return commoityInfoService.getCommodityList(20001);
    }

    @RequestMapping("/getShoppingCart")
    public List<CommodityInfo> getShoppingCart() {
        return shoppingService.getShoppingCart(10001);
    }

    @RequestMapping("/buy")
    public void buy() {
        Map<Integer, Integer> map = new HashMap<>();
        map.put(1, 2);
        shoppingService.orderCommodity(10001, map, 1);
    }

    @RequestMapping("/sale")
    public int sale() {
      return sellService.getSale(1);
    }


}
